package com.itheima.Controller;

import com.itheima.mapper.StudentMapper;
import com.itheima.pojo.*;
import com.itheima.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/students")
@RestController
public class StudentController {
    @Autowired
    private StudentService studentService;


    //查询

    @GetMapping
    public Result page(StudentQueryParam studentQueryParam) {
        PageResult pageResult = studentService.page(studentQueryParam);
        return Result.success(pageResult);
    }

    //    删除
    @DeleteMapping("/{ids}")
    public Result info(@PathVariable List<Integer> ids) {
        studentService.delete(ids);
        return Result.success();

    }


    //    新增
    @PostMapping
    public Result add(@RequestBody Student student) {
        return Result.success(studentService.add(student));
    }

    //    回显
    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Integer id) {
        Student student = studentService.getInto(id);
        return Result.success(student);

    }

    //    修改
    @PutMapping
    public Result update(@RequestBody Student stu) {
        studentService.update(stu);
        return Result.success();


    }

    //    违纪
    @PutMapping("/violation/{id}/{score}")
    public Result updateViolation(@PathVariable("id") Integer id, @PathVariable("score") Short score) {
        //调用Service层执行修改
        studentService.updateViolation(id, score);
        return Result.success();
    }




}
